package com.admin.business.voteStep;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 发起成立进度记录
 * @create: 2022-07-08 19:04:49
 **/
@Service("voteStep")
@Slf4j
public class VoteStepService{

    @Resource
    VoteStepDao voteStepDao;

    /**
     * 添加发起成立进度记录,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - step_id:相关步骤id ：基本信息id，
     *                   - property:物业公司名称或id
     *                   - planned_speed:成立进度记录
     *                   - complete_state:完成状态:0、未完成 1、已完成
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return addVoteStep(CDO cdoRequest) {
        voteStepDao.addVoteStep(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新发起成立进度记录数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - step_id:相关步骤id ：基本信息id，
     *                   - property:物业公司名称或id
     *                   - planned_speed:成立进度记录
     *                   - complete_state:完成状态:0、未完成 1、已完成
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVoteStepById(CDO cdoRequest) {
        int affectedRows = voteStepDao.updateVoteStepById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除发起成立进度记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteStepById(CDO cdoRequest){
        int affectedRows = voteStepDao.deleteVoteStepById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除发起成立进度记录数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteStep(CDO cdoRequest) {
        int affectedRows = voteStepDao.deleteVoteStep(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取发起成立进度记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteStepById(CDO cdoRequest) {
        CDO cdoMapperResult = voteStepDao.getVoteStepById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取发起成立进度记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteStep(CDO cdoRequest) {
        CDO cdoMapperResult = voteStepDao.getVoteStep(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取发起成立进度记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteStepList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteStepDao.getVoteStepList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = voteStepDao.getVoteStepListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取发起成立进度记录数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteStepListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteStepDao.getVoteStepListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = voteStepDao.getVoteStepListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
